#ifndef MOCHA_DETAIL_OBJECT_IMPORTER_HPP_INCLUDED
#define MOCHA_DETAIL_OBJECT_IMPORTER_HPP_INCLUDED

/**
 * @file 
 */

#include "mocha/plugin.hpp"

namespace mocha {
/**
 * Imports foreign (C) objects into C++ (adapted) objects.
 */
class object_importer {
public:
	virtual ~object_importer() {}
	/**
	 * Imports a foreign (C) object.
	 * @param object Object.
	 * @param destroy Function used to destroy the object.
	 * @return An adapted version of the object.
	 */
	virtual void* import(void* object, mocha_plugin_destroy_func_t destroy) const = 0;
};
/**
 * Basic importer that passes objects through without actually adapting them.
 */
class null_object_importer : public object_importer {
public:
	virtual ~null_object_importer() {}
	virtual void* import(void* object, mocha_plugin_destroy_func_t destroy) const {
		return object;
	}
};
/**
 * Basic importer that wraps a foreign (C) object within a self-managing C++ object.
 * @param T Imported type implementing the imported concept.
 * @see imported_object
 */
template<typename T>
class c_object_importer : public object_importer {
public:
	typedef typename T::unadapted_type unadapted_type;
	virtual ~c_object_importer() {}
	virtual void* import(void* object, mocha_plugin_destroy_func_t destroy) const {
		return new T(static_cast<unadapted_type*>(object), destroy);
	}
protected:
	const c_object_importer& get() const {
		return *this;
	}
};
}

#endif

